package com.ztgf.shopping.api.client.epg;

import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgBannerBO;
import com.ztgf.shopping.models.dto.epg.EpgBannerDTO;
import com.ztgf.shopping.models.service.epg.IEpgBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * banner对外接口类
 *
 * @author mxli
 * @Date 2019-11-30 01:47:53
 */

@RestController
@RequestMapping("/api/epgBanner")
@Slf4j
@Api(value = "EpgBannerApiController",tags = "BannerApi表接口")
public class EpgBannerApiController {

    @DubboReference
    private IEpgBannerService epgBannerService;

    /**
     * banner列表 根据功能id
     * @param moduleId 功能id
     * @return
     */
    @ApiOperation(value = "Banner列表 根据功能id",notes = "Banner列表 根据功能id")
    @PostMapping("/getListByModuleId")
    public Result<List<EpgBannerDTO>> getListByModuleId(Long moduleId){
        EpgBannerBO epgBannerBO = new EpgBannerBO();
        epgBannerBO.setModuleId(moduleId);
        List<EpgBannerDTO> epgBannerDTOList = epgBannerService.getBySelectBannerInfoNoPage(epgBannerBO);
        return new Result<>(epgBannerDTOList);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找Banner表",notes = "根据id查找Banner表")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    public Result<EpgBannerDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        EpgBannerDTO epgBannerDTO = epgBannerService.selectById(id);
        return new Result<>(epgBannerDTO);
    }

    @ApiOperation(value = "Banner列表",notes = "Banner列表")
    @PostMapping("/querySelectList")
    public Result<List<EpgBannerDTO>> querySelectList( EpgBannerBO epgBannerBO){
        if(null == epgBannerBO)
            return new Result<>(CodeEnum.FAIL_100002 );
        List<EpgBannerDTO> epgBannerDTOList = epgBannerService.getBySelectBannerInfoNoPage(epgBannerBO);
        return new Result<>(epgBannerDTOList);
    }
}
